/*
 * Copyright (C), 2007-2018, 铭师堂教育科技有限公司
 * FileName: CommonService.java
 * Author:   zhaoyi
 * Date:     2018年4月23日 下午5:55:54
 * Description: //模块目的、功能描述      
 * History: //修改记录
 * <author>      <time>      <version>    <desc>
 * 修改人姓名             修改时间            版本号                  描述
 */
package com.secsbrain.cmdb.biz.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.secsbrain.cmdb.biz.IHostService;
import com.secsbrain.cmdb.biz.IIdclevelService;
import com.secsbrain.cmdb.biz.IRackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.secsbrain.cmdb.biz.ICabinetService;
import com.secsbrain.cmdb.biz.IIdcService;
import com.secsbrain.cmdb.biz.IIspService;
import com.secsbrain.cmdb.biz.ISupplierService;
import com.secsbrain.cmdb.dal.model.Cabinet;
import com.secsbrain.cmdb.dal.model.Host;
import com.secsbrain.cmdb.dal.model.Idc;
import com.secsbrain.cmdb.dal.model.Idclevel;
import com.secsbrain.cmdb.dal.model.Isp;
import com.secsbrain.cmdb.dal.model.Rack;
import com.secsbrain.cmdb.dal.model.Supplier;

/**
 * 通用服务
 *
 * @author zhaoyi
 */
@Service
public class CommonService {
	
	@Autowired
    IIdcService idcService;

	@Autowired
    IIdclevelService idclevelService;
	
	@Autowired
    ISupplierService supplierService;
	
	@Autowired
    ICabinetService cabinetService;
	
	@Autowired
    IRackService rackService;
	
	@Autowired
    IIspService ispService;
	
	@Autowired
    IHostService hostService;
	
	public Map<Long, String> getIdclevelMap(){
		Map<Long, String> idclevelMap=new HashMap<>();
		List<Idclevel> idclevelList=idclevelService.selectList(new Idclevel());
		for(Idclevel idclevel:idclevelList){
			idclevelMap.put(idclevel.getId(),idclevel.getName());
		}
		return idclevelMap;
	}
	
	/**
	 * 功能描述: <br>
	 * 获取机房Map: key-机房Id,value-机房名称
	 *
	 * @return
	 */
	public Map<Long, String> getIdcMap(){
		Map<Long, String> idcMap=new HashMap<>();
		List<Idc> idcList=idcService.selectList(new Idc());
		for(Idc idc:idcList){
			idcMap.put(idc.getId(),idc.getName());
		}
		return idcMap;
	}
	
	public Map<Long, String> getCabinetMap(){
		Map<Long, String> cabinetMap=new HashMap<>();
		List<Cabinet> cabinetList=cabinetService.selectList(new Cabinet());
		for(Cabinet cabinet:cabinetList){
			cabinetMap.put(cabinet.getId(),cabinet.getName());
		}
		return cabinetMap;
	}
	
	public Map<Long, String> getRackMap(){
		Map<Long, String> rackMap=new HashMap<>();
		List<Rack> rackList=rackService.selectList(new Rack());
		for(Rack rack:rackList){
			rackMap.put(rack.getId(),rack.getName());
		}
		return rackMap;
	}
	
	public Map<Long, List<Cabinet>> getCabinetMapIdcKey(){
		Map<Long, List<Cabinet>> cabinetListMap=new HashMap<>();
		List<Cabinet> list=cabinetService.selectList(new Cabinet());
		for(Cabinet cabinet:list){
			Long idcId=cabinet.getIdcId();
			List<Cabinet> subList=null;
			if(cabinetListMap.containsKey(idcId)){
				subList=cabinetListMap.get(idcId);
			}else{
				subList=new ArrayList<Cabinet>();
			}
			subList.add(cabinet);
			cabinetListMap.put(idcId, subList);
		}
		return cabinetListMap;
	}
	
	public Map<Long, List<Rack>> getRackMapCabinetKey(){
		Map<Long, List<Rack>> cabinetListMap=new HashMap<>();
		List<Rack> list=rackService.selectList(new Rack());
		for(Rack rack:list){
			Long cabinetId=rack.getCabinetId();
			List<Rack> subList=null;
			if(cabinetListMap.containsKey(cabinetId)){
				subList=cabinetListMap.get(cabinetId);
			}else{
				subList=new ArrayList<Rack>();
			}
			subList.add(rack);
			cabinetListMap.put(cabinetId, subList);
		}
		return cabinetListMap;
	}
	
	public Map<Long, String> getSupplierMap(){
		Map<Long, String> supplierMap=new HashMap<>();
		List<Supplier> supplierList=supplierService.selectList(new Supplier());
		for(Supplier supplier:supplierList){
			supplierMap.put(supplier.getId(),supplier.getName());
		}
		return supplierMap;
	}
	
	public Map<Long, String> getIspMap(){
		Map<Long, String> ispMap=new HashMap<>();
		List<Isp> ispList=ispService.selectList(new Isp());
		for(Isp isp:ispList){
			ispMap.put(isp.getId(),isp.getName());
		}
		return ispMap;
	}
	
	public Map<Long, Host> getHostMap(){
		Map<Long, Host> hostMap=new HashMap<>();
		List<Host> hostList=hostService.selectList(new Host());
		for(Host host:hostList){
			hostMap.put(host.getId(),host);
		}
		return hostMap;
	}
	
}
